import { request } from 'ice';

export interface QueryParams {
  /** 订单号 */
  orderNo?: string;
  /** 物流编号 */
  shippingLabel?: string;
  /** 卖家编号 */
  sellerNo?: string;
  /** 发货时间 开始 */
  startShippingTime?: number;
  /** 发货时间 截止 */
  endShippingTime?: number;
  sendTime?: number[];
  receiveTime?: number[];
}

/** 已经收货列表 */
export const alreadyReceiveList = (pageParams: ICommon.PageParams, formData: QueryParams): Promise<any> => {
  const params = {
    ...pageParams,
    ...formData,
    startShippingTime: (formData?.sendTime || [])[0]?.valueOf(),
    endShippingTime: (formData?.sendTime || [])[1]?.valueOf(),
    startReceiveTime: (formData?.receiveTime || [])[0]?.valueOf(),
    endReceiveTime: (formData?.receiveTime || [])[1]?.valueOf(),
    sendTime: undefined,
    receiveTime: undefined,
  };
  return request.get('/operating/receive/already/page', { params }).then((res) => ({
    total: res?.total || 0,
    list: res?.data || [],
  }));
};

/** 待收货列表 */
export const stayReceiveList = (pageParams: ICommon.PageParams, formData: QueryParams): Promise<any> => {
  const params = {
    ...pageParams,
    ...formData,
    startTime: (formData?.sendTime || [])[0]?.valueOf(),
    endTime: (formData?.sendTime || [])[1]?.valueOf(),
    sendTime: undefined,
  };
  return request.get('/operating/receive/stay/page', { params }).then((res) => ({
    total: res?.total || 0,
    list: res?.data || [],
  }));
};
